﻿using Axis.Web.Administrator.Global;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using Axis.BusinessObject.Core;

namespace Axis.Web.Views.Global
{
    public class CMemberCore : System.Web.UI.Page
    {
        public string GetMemberInputValueExtend(string inputValue)
        {
            var MEMBER_ID = 0;
            var member = new CMemberList();
            if (Session["MEMBERINFO"] != null)
            {
                member = Session["MEMBERINFO"] as CMemberList;
                MEMBER_ID = member.ID;
            }

            string extend = string.Format("<InputValue UserID='{0}' ID='{0}' SecrectToken='{1}' ", member.ID, member.SecrectToken);
            inputValue = inputValue.Replace("<InputValue", extend);
            return inputValue;
        }
        public string GetMemberInputValue(HttpContext context = null)
        {
            var member = new CMemberList();
            if (Session["MEMBERINFO"] != null)
            {
                member = Session["MEMBERINFO"] as CMemberList;
            }
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement("InputValue");
            doc.AppendChild(root);
           // root.SetAttribute("UserID", CSecurity.MEMBER_ID.ToString());
            root.SetAttribute("ID", member.ID.ToString());
            root.SetAttribute("UserID", member.ID.ToString());
            root.SetAttribute("SecrectToken", member.SecrectToken);
            if (context != null)
            {
                HttpRequest request = context.Request;
                HttpResponse response = context.Response;
                StringBuilder qsXml = new StringBuilder();
                string[] allKeys = request.Form.AllKeys;
                if (allKeys.Length == 0)
                {
                    allKeys = request.QueryString.AllKeys;
                }
                foreach (string pKey in allKeys)
                {
                    string key = pKey.Trim();
                    string value = request[key].Trim();
                    if (key == "page")
                        key = "PageIndex";
                    if (key == "rows")
                        key = "RowsPerPage";
                    if (key.Equals("OldPassword") || key.Equals("NewPassword"))
                    {
                        value = CSecurity.GetMD5HashData(value);
                    }
                    root.SetAttribute(key, value);
                }
            }
            return doc.OuterXml;
        }
    }
}